package cn.huhaoran.yaoyaolingxian.actions;

import cn.huhaoran.yaoyaolingxian.ui.GenerateCode;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.vfs.VirtualFile;

import javax.swing.*;
import java.util.Objects;

/**
 * 右键单击文件后的弹出页面
 *
 * @author huhaoran
 * @description:
 * @date 2024/7/14
 */
public class newNavDestinationPageAnAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        // 设置图标
        Presentation presentation = getTemplatePresentation();
        Icon myIcon = IconLoader.getIcon("/icons/ic_public_file_filled.svg", newNavDestinationPageAnAction.class);
        presentation.setIcon(myIcon);
        String projectBasePath = Objects.requireNonNull(e.getProject()).getBasePath();
        System.out.println("项目路径 = " + projectBasePath);
        VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE);
        // 弹出对话框
        GenerateCode dialog = new GenerateCode(e,file);
        dialog.pack();
        dialog.setVisible(true);
        // 在窗口显示之后请求焦点
        SwingUtilities.invokeLater(() -> dialog.pageName.requestFocusInWindow());
    }
}
